<template>
  <div>
    <!-- 面包屑导航区 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>商品管理</el-breadcrumb-item>
      <el-breadcrumb-item>商品列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片视图 -->
    <el-card>
      <el-row :gutter="20">
         <el-col :span="10"
          ><div class="text item">
            <el-input placeholder="请输商品名" class="input-with-select"
            v-model="queryInfo.query" clearable @clear="getGoodsList">
              <el-button slot="append" icon="el-icon-search" @click="getGoodsList"></el-button>
            </el-input></div
        ></el-col>
        <el-col :span="4">
          <el-button type="primary" @click="goAddPage">添加商品</el-button>
        </el-col>
      </el-row>
      <!-- 表格数据 -->
       <el-tabs v-model="activeGoodsId" @tab-click="handleClick">
        <el-tab-pane label="全部商品" name="2">
          <GoodsList :goodsList="goodsList" @getGoodsList="getGoodsList"></GoodsList>
        </el-tab-pane>
        <el-tab-pane label="已上架商品" name="1"><GoodsList @getGoodsList="getGoodsList"  :goodsList="goodsList"></GoodsList></el-tab-pane>
        <el-tab-pane label="未上架商品" name="0"><GoodsList @getGoodsList="getGoodsList" :goodsList="goodsList"></GoodsList></el-tab-pane>
      </el-tabs>
     <!-- 分页区域 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryInfo.pagenum"
        :page-sizes="[5, 10, 15, 20]"
        :page-size="queryInfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        background
      ></el-pagination>
    </el-card>
   </div>
</template>

<script>
// import OssUpload from '../upload/OssUpload'
import GoodsList from './components/GoodsList'
export default {
  data () {
    return {
      queryInfo: {
        query: '',
        pagenum: 1,
        pagesize: 10
      },
      // 商品列表
      goodsList: [],
      // 商品总数
      total: 0,
      // 控制商品查询
      activeGoodsId:"2",
    }
  },
  components:{
    GoodsList
  },
  created(){
    this.getGoodsList()
  },
  methods: {
    // 获取对应的商品列表
    async getGoodsList () {
      console.log("ddd",this.activeGoodsId)
      const {data:res} = await this.$http.get(`/xuanmall/spumessage/list?publishStatus=${this.activeGoodsId}&page=${this.queryInfo.pagenum}&limit=${this.queryInfo.pagesize}&key=${this.queryInfo.query}`)
      console.log(res)
      this.total = res.page.totalCount
      this.goodsList =[],
       res.page.list.forEach(value =>{
         var data = {};
         data.id = value.id
         data.spuName = value.spuName
         data.images = value.images[0]
         data.price = value.price
         data.weight = value.weight
         data.stockCount = value.stockCount
         data.publishStatus = value.publishStatus
         this.goodsList.push(data)
       })
    },
    // 点击标签页
    handleClick(tab){
      console.log(tab.name);
      this.activeGoodsId = tab.name
      this.getGoodsList()
    },
    handleSizeChange (newSize) {
      this.queryInfo.pagesize = newSize
      this.getGoodsList()
    },
    handleCurrentChange (newSize) {
      this.queryInfo.pagenum = newSize
      this.getGoodsList()
    },
   goAddPage () {
      this.$router.push('/goodsadd')
    }

  }
}
</script>

<style lang="less" scoped>

</style>
